package com.liming.resource.webapp.wicket.page;

import com.liming.core.web.wicket.BasePage;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.data.DataView;
import org.apache.wicket.markup.repeater.data.ListDataProvider;
import org.apache.wicket.model.AbstractReadOnlyModel;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @类描述：
 * @创建人：sunlf
 * @创建时间：2014-03-29 下午1:50
 * @修改人：
 * @修改时间：
 * @修改备注：
 */

public class VideoPage extends BasePage {
    public VideoPage() {
        List<File> messageList = AllEntity();
        ListDataProvider<File> listDataProvider = new ListDataProvider<File>(messageList);
        add(new DataView<File>("fileRows", listDataProvider) {
            private static final long serialVersionUID = 1L;

            @Override
            protected void populateItem(final Item<File> item) {
                final File file;
                file = item.getModelObject();

                item.add(new Label("name", file.getName()));
                item.add(new Label("describe", file.getDescribe()));
                item.add(new Label("size", file.getSize()));
                item.add(new Label("createDateData", file.getCreateDate()));
                item.add(new Label("version", file.getVersion()));
                item.add(AttributeModifier.replace("class", new AbstractReadOnlyModel<String>() {
                    private static final long serialVersionUID = 1L;

                    @Override
                    public String getObject() {
                        return (item.getIndex() % 2 == 1) ? "even" : "odd";
                    }
                }));
            }
        });
    }

    private List<File> AllEntity() {
        List<File> fileList = new ArrayList<File>();
        File file1 = new File();

        file1.setName("红旗H7宣传短片.mp4");
        file1.setDescribe("用于宣传红旗H7产品");
        file1.setSize("19M");
        file1.setCreateDate("2014-03-29");
        file1.setVersion("2.1");

        fileList.add(file1);
        return fileList;
    }

    class File implements Serializable {
        String name;

        String describe;

        String version;

        public String getVersion() {
            return version;
        }

        public void setVersion(String version) {
            this.version = version;
        }


        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getDescribe() {
            return describe;
        }

        public void setDescribe(String describe) {
            this.describe = describe;
        }

        public String getSize() {
            return size;
        }

        public void setSize(String size) {
            this.size = size;
        }

        public String getCreateDate() {
            return createDate;
        }

        public void setCreateDate(String createDate) {
            this.createDate = createDate;
        }

        String size;

        String createDate;

    }
}
